# Licensed under the GNU Lesser General Public License, version 2.1 (LGPL-2.1)
# Full text is available at:
#
#    http://www.gnu.org/licenses/lgpl-2.1.txt
#
# This file is part of cyg-get.
#
#    cyg-get is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as
#    published by the Free Software Foundation, either version 2.1 of
#    the License, or (at your option) any later version.
#
#    cyg-get is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public
#    License along with cyg-get.
#
#    If not, see <http://www.gnu.org/licenses/>.

package Cygwin::Package;

use strict;

sub new {
    my $class = shift;
    my $this = bless {
        install => [],
        source => [],
        requires => [],
        categories => [],
        sdesc => '',
        ldesc => '',
    }, $class;
    
    $this->{name} = shift;
    $this->{ver} = shift;
    
    $this->{name} = "" unless defined($this->{name});
    $this->{ver} = ""  unless defined($this->{ver});
    
    return $this;
}

sub dbLine {
    my $this = shift;
    my $line = shift;
    
    $line =~ m{^[^ ]+ (.*)-([^-]+)-[^-]+\..*$};
    
    $this->{name} = $1;
    $this->{ver} = $2;
}

sub compareTo {
    my $this = shift;
    my $that = shift;
    
    my $v = ($this->{ver} < $that->{ver})?(0):(1);
    if( $v == 0 ) {
        $v = ($this->{ver} == $that->{ver})?(0):(-1);
    }
    return $v;
}

sub toString {
    my $this = shift;
    
    return sprintf("%s : %s", $this->{name}, $this->{sdesc});
}

1;